package ru.store;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import ru.store.book.Book;

public class StubStore implements IStore {
	private Map<String, Map<String, Item>> items = new HashMap<String, Map<String, Item>>();
	
	public StubStore()
	{
		super();
	}
	@Override
	public int getTotalAmount() {
		return items.size();
	}

	@Override
	public void addItem(Item item) throws Exception {
		if (items.get(item.getType()) == null)
			items.put(item.getType(), new HashMap<String, Item>());
		if ( items.get(item.getType()).get(item.getId()) == null )
			items.get(item.getType()).put(item.getId(), item);
		else
			throw new Exception(String.format("Store.Addbook: ID %s is not unique!", item.getId()));
	}

	@Override
	public void sellItem(String type, String id, int count) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Item getItem(String type, String id) {
		Map<String, Item> tmp = items.get(type);
		if(tmp == null)
			return null;
		return tmp.get(id);
	}

	@Override
	public Map<String, Item> getItems(String type) {
		return items.get(type);
	}

}
